﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/OnlyAuthenticated/GeneratorMasterPage.master"
    Inherits="OnlyAuthenticated_OnlyManagers_EditModele" ValidateRequest="false" CodeBehind="EditModele.aspx.cs" %>


<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="GeneratorPageContent">
    <asp:LoginName ID="LoginName" runat="server" Visible="False" />
    <h2>Modele
    </h2>
    <br />
    <h3>
        <asp:Label ID="Label1" runat="server" Text="Introducere model nou:"></asp:Label>
    </h3>

    <table style="width: 775px;">
        <tr>
            <td width="40%">
                <asp:Label ID="Label3" runat="server" Text="In specialitatea:"></asp:Label>
                <br />
                <asp:DropDownList ID="DropDownListSpecialitati" runat="server"
                    DataSourceID="SpecialitatiSqlDataSource" DataTextField="NumeSpecialitate"
                    DataValueField="NumeSpecialitate">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SpecialitatiSqlDataSource" runat="server"
                    ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
                    SelectCommand="SELECT [ID], [NumeSpecialitate] FROM [DenumiriSpecialitati] ORDER BY [NumeSpecialitate]">
                </asp:SqlDataSource>
            </td>
            <td style="width: 25%">
                <asp:Label ID="Label4" runat="server" Text="Denumire Model:"></asp:Label>
                <br />
                <asp:TextBox ID="TextBoxDenumireModel" runat="server"></asp:TextBox>
            </td>
            <td style="text-align: center">
                <asp:Label ID="Label6" runat="server" Text="Mareste/Micsoreaza fereastra modelului:"></asp:Label>
                <br />
                <input id="Button1" type="button" value="+" onclick="increaseTextBox1Hight()" style="width: 25px" />
                <input id="Button2" type="button" value="-" onclick="decreaseTextBox1Hight()" style="width: 25px" />
                <br />
                <br />
                <asp:Button ID="AdaugaModelulButton" runat="server" Text="Adauga Modelul !"
                    OnClick="AdaugaModelulButton_Click" ForeColor="Red" />
            </td>
        </tr>
    </table>

    <asp:Label ID="Label5" runat="server" Text="Textul Modelului:"></asp:Label>

    <br />
    <asp:TextBox ID="TextBoxTextModel" runat="server" ClientIDMode="Static" TextMode="MultiLine"
        Width="775px" BorderColor="#3399FF" Height="150px" BorderWidth="1px"></asp:TextBox>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <h3>
        <asp:Label ID="Label2" runat="server" Text="Vizualizare, Editare si Stergere modele:"></asp:Label></h3>
    <div>
         (daca nu esti administrator, ai voie sa modifici doar modelele tale)
    </div>
    <br />

    <table style="width: 775px;">
        <tr>
            <td style="width: 40%">
                <asp:Label ID="Label7" runat="server" Text="Din specialitatea:"></asp:Label>
                <br />
                <asp:DropDownList ID="DropDownListSpecialitati0" runat="server" DataSourceID="SpecialitatiSqlDataSource0"
                    DataTextField="NumeSpecialitate" DataValueField="NumeSpecialitate" AutoPostBack="True">
                </asp:DropDownList>
                <br />
                <br />
                <br />
                <br />
                <asp:Label ID="Label11" runat="server" Text="Denumirea Modelului:"></asp:Label>
                <asp:TextBox ID="TextBoxDenumireModelEdit" runat="server" ClientIDMode="Static"></asp:TextBox>
                <asp:SqlDataSource ID="SpecialitatiSqlDataSource0" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
                    SelectCommand="SELECT [ID], [NumeSpecialitate] FROM [DenumiriSpecialitati] ORDER BY [NumeSpecialitate]"></asp:SqlDataSource>
            </td>
            <td style="width: 20%; text-align: center;">
                <asp:Label ID="Label8" runat="server" Text="Modele Existente:"></asp:Label>
                <br />
                <asp:DropDownList ID="DropDownListModeleExistente" runat="server" DataSourceID="ModeleSqlDataSource2"
                    DataTextField="NumeModel" DataValueField="NumeModel" AutoPostBack="True" Width="100%">
                </asp:DropDownList>
                <br />
                <br />
                <br />
                <br />
                <asp:LoginView ID="LoginView3" runat="server">
                    <RoleGroups>
                        <asp:RoleGroup Roles="managers">
                            <ContentTemplate>
                                <asp:Button ID="SaveButton" runat="server" ClientIDMode="Static" Enabled="False" ForeColor="Red"
                                    OnClick="SaveButton_Click" Text="Salveaza Modificarile" />
                            </ContentTemplate>
                        </asp:RoleGroup>
                        <asp:RoleGroup Roles="users">
                            <ContentTemplate>
                                <asp:Button ID="SaveButton2" runat="server" ClientIDMode="Static" Enabled="False" ForeColor="Red"
                                    OnClick="SaveButton_Click" Text="Salveaza Modificarile" />
                            </ContentTemplate>
                        </asp:RoleGroup>
                    </RoleGroups>
                </asp:LoginView>
                <asp:SqlDataSource ID="ModeleSqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
                    SelectCommand="SELECT [ID], [NumeModel], [TextModel], [Specialitate], [UserEditor] FROM [DenumiriModele] WHERE ([Specialitate] = @Specialitate) ORDER BY [NumeModel]">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="DropDownListSpecialitati0" Name="Specialitate" PropertyName="SelectedValue"
                            Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </td>
            <td style="text-align: center; width: 40%;">
                <asp:Label ID="Label9" runat="server" Text="Mareste/Micsoreaza fereastra modelului:"></asp:Label>
                <br />
                <input id="Button7" type="button" value="+" onclick="increaseTextBox2Hight()" style="width: 25px" />
                <input id="Button8" type="button" value="-" onclick="decreaseTextBox2Hight()" style="width: 25px" />
                <br />
                <br />
                <br />
                <br />
                <asp:LoginView ID="LoginView2" runat="server">
                    <RoleGroups>
                        <asp:RoleGroup Roles="managers">
                            <ContentTemplate>
                                <asp:Button ID="DeleteButton" runat="server" ForeColor="Red" Enabled="True"
                                    OnClick="DeleteButton_Click" Text="Sterge Modelul !" />
                            </ContentTemplate>
                        </asp:RoleGroup>
                        <asp:RoleGroup Roles="users">
                            <ContentTemplate>
                                <asp:Button ID="DeleteButton2" runat="server" ForeColor="Red" Enabled="True"
                                    OnClick="DeleteButton_Click" Text="Sterge Modelul !" />
                            </ContentTemplate>
                        </asp:RoleGroup>
                    </RoleGroups>
                </asp:LoginView>
                <br />
            </td>
        </tr>
    </table>


    &nbsp;<asp:Label ID="Label10" runat="server" Text="Textul Modelului:"></asp:Label>
    <br />
    <asp:DataList ID="DataList1" runat="server"
        DataSourceID="ModelTextSqlDataSource" DataKeyField="ID">
        <ItemTemplate>
            <asp:TextBox ID="TextBoxTextModelEdit" runat="server" TextMode="MultiLine" Width="775px"
                BorderColor="#3399FF" Height="150px" BorderWidth="1px" AutoPostBack="False" ClientIDMode="Static"
                Text='<%# Eval("TextModel") %>' />
            <br />
            <br />
        </ItemTemplate>
    </asp:DataList>
    <asp:SqlDataSource ID="ModelTextSqlDataSource" runat="server"
        ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
        SelectCommand="SELECT [ID], [NumeModel], [TextModel] FROM [DenumiriModele] WHERE ([NumeModel] = @NumeModel)">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownListModeleExistente"
                Name="NumeModel" PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

    <br />

    <br />
    <br />
    <br />
    <br />
    <br />



    <%--  // todo: these may not be needed --%>

    <asp:SqlDataSource ID="ModeleSqlDataSource" runat="server"
        ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
        DeleteCommand="DELETE FROM [DenumiriModele] WHERE [ID] = @ID"
        InsertCommand="INSERT INTO [DenumiriModele] ([NumeModel], [TextModel], [Specialitate], [UserEditor]) VALUES (@NumeModel, @TextModel, @Specialitate, @UserEditor)"
        SelectCommand="SELECT [ID], [NumeModel], [TextModel], [Specialitate], [UserEditor] FROM [DenumiriModele]"
        UpdateCommand="UPDATE [DenumiriModele] SET [NumeModel] = @NumeModel, [TextModel] = @TextModel, [Specialitate] = @Specialitate, [UserEditor] = @UserEditor WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="NumeModel" Type="String" />
            <asp:Parameter Name="TextModel" Type="String" />
            <asp:Parameter Name="Specialitate" Type="String" />
            <asp:Parameter Name="UserEditor" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="NumeModel" Type="String" />
            <asp:Parameter Name="TextModel" Type="String" />
            <asp:Parameter Name="Specialitate" Type="String" />
            <asp:Parameter Name="UserEditor" Type="String" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    
    <asp:HiddenField ID="HiddenModelText" runat="server" ClientIDMode="Static"/>

    <script type="text/javascript">
        $("#TextBoxTextModelEdit, #TextBoxDenumireModelEdit").change(function () {
            $("#SaveButton").removeAttr("disabled");
            $('input[id="HiddenModelText"]').val($("#TextBoxTextModelEdit").val());
        });

        function increaseTextBox1Hight() {
            var x = parseInt(document.getElementById("TextBoxTextModel").style.height.replace("px", ""));
            document.getElementById("TextBoxTextModel").style.height = x + 100 + 'px';
        }

        function decreaseTextBox1Hight() {
            var x = parseInt(document.getElementById("TextBoxTextModel").style.height.replace("px", ""));
            if (x - 100 > 30) {
                document.getElementById("TextBoxTextModel").style.height = x - 100 + 'px';
            }
        }

        function increaseTextBox2Hight() {
            var x = parseInt(document.getElementById("TextBoxTextModelEdit").style.height.replace("px", ""));
            document.getElementById("TextBoxTextModelEdit").style.height = x + 100 + 'px';
        }

        function decreaseTextBox2Hight() {
            var x = parseInt(document.getElementById("TextBoxTextModelEdit").style.height.replace("px", ""));
            if (x - 100 > 30) {
                document.getElementById("TextBoxTextModelEdit").style.height = x - 100 + 'px';
            }
        }

    </script>

</asp:Content>
